#include "OvertakeAgent.h"

using namespace MathUtility;

OvertakeAgent::OvertakeAgent()
{
	/*
	float angle = -180.0f;
	for (int i = 0; i < 36; i++)
	{
		insertCharge(Charge(-80, convertDegToRad(angle)), i);
		
		angle += 10.0f;
	}
	*/
}


OvertakeAgent::~OvertakeAgent()
{

}

void OvertakeAgent::update(CarState& cs, const float dt)
{
	clear();

	
	for (int i = 5; i < 31; i++)
	{
		float angle = (-180 + (i*10.0f));
		if (cs.getOpponents(i) < 100.0f)
		{
			Charge charge;
			charge.setLength(cs.getOpponents(i));
			charge.setAngle(convertDegToRad(angle));
			charge.update();
		
			insertCharge(charge, field.size());
		}
		
	}
	
}

void OvertakeAgent::calculatePotentialForOptions(DriverOption* const options, unsigned int size)
{
	for (int i = 0; i < size; i++)
	{
		for (int j = 0; j < field.size(); j++)
		{
			float length = (options[i].getPosition() - field[j].getPosition()).length();
			
			options[i].addPotential(-20.f / sqrtf(length*0.25f));
		}
		
	}
	
}
